<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0,
           maximum-scale=1.0, scaminimum-le=1.0"/>
    <title>angular-service</title>
    <!-- 此处讲解了服务的3中方式 -->
    <script src="js/angular.js"></script>
</head>
<body>
<!--初始化中全部是以key=value来书写的-->
    <div ng-app="myApp">
        <div ng-controller="thridController">
            {{name}}
        </div>
    </div>
</body>

<script type="text/javascript">
    var app=angular.module("myApp",[]);
    //这个是直接返回的是对象;
//    app.provider('providerService01', function () {
//    provider可以在config中配置属性;
//        this.$get= function () {
//            return {msg:"this is message"};
//        }
//    });
//
//    app.service('serviceService', function () {
//        return {msg:"this is service"};
//    });
//
//    app.factory('factoryService', function () {
//        return "this is factory";
//    });

    //此处通过set与get返回
    app.provider('providerService01', function () {
//        provider可以在config中配置属性;
        var mName='';
        var servise={};
        this.$get= function () {
            servise.setName= function (name) {
                mName=name;
            }

            servise.getName= function () {
                return mName;
            }

            return servise;
        }
    });

    app.service('serviceService', function () {
        return {msg:"this is service"};
    });

    app.factory('factoryService', function () {
        return "this is factory";
    });


    app.controller("thridController",["$scope","providerService01","serviceService","factoryService",
        function ($scope,providerService01,serviceService,factoryService) {
            providerService01.setName("我感觉这个还不错哦");
        $scope.name=providerService01.getName();
        console.log(serviceService);
        console.log(factoryService);
    }]);
</script>
</html>